package com.alvv.aixiuhulian;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.graphics.Bitmap;
import android.net.http.SslError;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.webkit.SslErrorHandler;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class MainActivity extends Activity {
    private WebView mWebView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.ylx_web_view);
        mWebView = (WebView) findViewById(R.id.base_web_view);
        initWebSetting();
        loadWebView("http://xiao.alivv.net/index.php?m=Brand&c=Index&a=index&uid=1");
    }

    @SuppressLint("SetJavaScriptEnabled")
    private void initWebSetting() {
        WebSettings settings = mWebView.getSettings();
        // 设置初始的缩放
        mWebView.setInitialScale(1);
        settings = mWebView.getSettings();
        // 屏幕适配
        settings.setUseWideViewPort(true);
        // settings.setLoadWithOverviewMode(true);
        settings.setJavaScriptEnabled(true);
        // 这里支持缓存
        // settings.setCacheMode(WebSettings.LOAD_NO_CACHE);
        settings.setSupportZoom(true);// TODO 放大缩小
        settings.setBuiltInZoomControls(true);
        // settings.setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN); //
        // 支持内容重新布局
    }

    private void loadWebView(String url) {
        mWebView.loadUrl(url);
        mWebView.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {

                return true;
            }

            @Override
            public void onPageStarted(WebView view, String url, Bitmap favicon) {
                super.onPageStarted(view, url, favicon);
                // showProgressDialog();
            }

            @Override
            public void onPageFinished(WebView view, String url) {
                super.onPageFinished(view, url);
                // disMissDialog();
            }

            @Override
            public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
                super.onReceivedSslError(view, handler, error);
                // disMissDialog();
            }
        });
        mWebView.setWebChromeClient(new WebChromeClient() {
            @Override
            public void onProgressChanged(WebView view, int newProgress) {
                super.onProgressChanged(view, newProgress);

            }
        });
    }
}
